<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@taglib prefix="mvc" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="fmt" uri="http://www.springframework.org/tags" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>项目审核（学校科研室主任）</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=10,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
    <link rel="stylesheet" type="text/css" href="/lib/layui/layui/css/layui.css"/>
    <script type="text/javascript" src="/js/news/jquery-1.9.1.js"></script>
    <script src="/js/base/base.js" type="text/javascript" charset="utf-8"></script>
    <script src="../../js/jquery/jquery.cookie.js"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery.ui.widget.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery.iframe-transport.js" type="text/javascript"
            charset="utf-8"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery.fileupload.js" type="text/javascript" charset="utf-8"></script>
    <script type="text/javascript" src="/js/common/fileupload.js"></script>
    <script type="text/javascript" src="/lib/layui/layui/layui.js"></script>
    <script type="text/javascript" src="/lib/layui/layui/layui.all.js"></script>
</head>
<style>
    .mbox {
        padding: 8px
    }

    .item img {
        height: 40px;
    }

    .btn {
        height: 37px;
    }

    .btn button {
        float: right;
    }

    .information {
        background: #e8f4fc;
        height: 30px;
        line-height: 30px;
    }

    .add {
        height: 30px;
    }

    .layui-form-item {
        margin-bottom: 5px;
    }

    .layui-input-inline {
        width: 300px !important;
    }

    .openFile input[type=file] {
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 18px;
        z-index: 99;
        opacity: 0;
    }

    .btn .layui-btn {
        margin-left: 10px;
    }

    .typeIpt {
        line-height: 30px;
        margin-left: 10px;
    }

    .layui-table-tool {
        display: none;
    }

    .layui-form-label {
        width: 100px;
    }

    .layui-table-view i{
        width: 18px;
        height: 18px;
        margin-top: 5px;
    }
</style>
<body>
<div class="mbox">
    <div class="item">
        <img src="../img/yeji.png" alt="" style="margin: 0 5px 0 20px;"> <span
            style="font-size: 22px;display: inline-block;vertical-align: middle;">项目审核（学校科研室主任）</span>
    </div>
    <hr class="layui-bg-blue">
    <div class="btn" style="display: inline-flex;">
        <span class="typeIpt layui-form">
            <input type="radio" checked class="approve" lay-filter="status" value="0" name="status" title="未审核"/>&nbsp;
            <input type="radio" lay-filter="status" value="1" name="status" title="通过"/>&nbsp;
            <input type="radio" lay-filter="status" value="2" name="status" title="退回"/>&nbsp;
            <input type="radio" lay-filter="status" value="8" name="status" title="不通过"/>&nbsp;
        </span>
    </div>
    <table class="layui-hide" id="test" lay-filter="test"></table>
</div>
</body>
</html>
<script type="text/html" id="barDemo">
    {{#  if(d.sDirectorLeaderStatus == 0){ }}
    <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="look">查看</a>
    <a class="layui-btn layui-btn-xs" value="1" lay-event="operate">通过</a>
    <a class="layui-btn layui-btn-xs layui-btn-danger" value="2" lay-event="operate">退回</a>
    <a class="layui-btn layui-btn-xs layui-btn-danger" value="8" lay-event="operate">不通过</a>
    {{#  } }}
</script>
<script>
    layui.use(['table', 'form', 'laydate', 'upload'], function () {
        var table = layui.table,
            form = layui.form,
            laydate = layui.laydate,
            upload = layui.upload;
        form.render()
        var tableData = table.render({
            elem: '#test'
            , url: '/rpmTopic/selectTopicS'
            , toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
            , defaultToolbar: ['']
            , where: {
                status: 0,
                deptId: $.cookie('deptId'),
            }
            , title: '用户数据表'
            , cols: [[
                {type: 'checkbox', fixed: 'left'},
                {field: 'planName', title: '计划名称'}
                , {field: 'topicName', title: '项目名称'}
                , {field: 'topicType', title: '项目类别',}
                , {field: 'research', title: '研究领域'}
                , {field: 'sDirectorLeaderStatus', title: '学校科研室主任审批状态',templet: function(d){
                        if(d.sDirectorLeaderStatus=='0'){
                            return '未审核'
                        }else if(d.sDirectorLeaderStatus=='1'){
                            return '通过'
                        }else if(d.sDirectorLeaderStatus=='2'){
                            return '退回'
                        }else if(d.sDirectorLeaderStatus=='8'){
                            return '不通过'
                        }else {
                            return''
                        }
                    }}
                , {field: 'teacheerStatus', title: '学院老师审批状态',templet: function(d){
                        if(d.teacheerStatus=='0'){
                            return '未审核'
                        }else if(d.teacheerStatus=='1'){
                            return '通过'
                        }else if(d.teacheerStatus=='2'){
                            return '退回'
                        }else if(d.teacheerStatus=='8'){
                            return '不通过'
                        }else {
                            return''
                        }
                    }}
                , {field: 'directorLeaderStatus', title: '学院教研主任审批状态',templet: function(d){
                        if(d.directorLeaderStatus=='0'){
                            return '未审核'
                        }else if(d.directorLeaderStatus=='1'){
                            return '通过'
                        }else if(d.directorLeaderStatus=='2'){
                            return '退回'
                        }else if(d.directorLeaderStatus=='8'){
                            return '不通过'
                        }else {
                            return''
                        }
                    }}
                , {
                    field: 'type', title: '操作', toolbar: '#barDemo'}
            ]]
            , page: true
            , parseData: function (res) { //res 即为原始返回的数据
                for (var i = 0; i < res.totleNum; i++) {
                    if (res.flag != false) {
                        return {
                            "code": 0, //解析接口状态
                            "data": res.object,//解析数据列表
                            "count": res.totleNum, //解析数据长度
                            "msg": res.msg,
                        };
                    } else {
                        return {
                            "msg": res.msg
                        }
                    }
                }
            }
        });
                form.on('radio(status)', function (data) {
                    tableData.reload({
                        where: {
                            status: data.value,
                            deptId: $.cookie('deptId'),
                        }
                    })
                });
                $.ajax({
                    url: '/Meetequipment/getuser',
                    type: 'get',
                    dataType: 'json',
                    success: function (res) {
                        $('table').attr('id', res.object.userId)
                    }
                });
                //监听行工具事件
                table.on('tool(test)', function(obj){
                    var data = obj.data;
                    var text = $(this).text();
                    var val = $(this).attr("value");
                    if (obj.event === 'operate') {
                        var sDirectorLeaderStatus = ''
                        if (val == '1') {
                            sDirectorLeaderStatus = 1   //通过等于1
                            layer.confirm('是否确认通过？', function (index) {
                            $.ajax({
                                url: '/rpmTopic/updateRpmTopic',
                                dataType: 'json',
                                type: 'get',
                                data:
                                     '&topicId=' + obj.data.topicId
                                    + '&planId=' + obj.data.planId
                                    + '&userId=' + data.userId
                                    + '&sDirectorLeaderStatus=' + sDirectorLeaderStatus
                                    +'&teacheerStatus='+'0',
                                success: function (res) {
                                    if (res.flag) {
                                        layer.close(index)
                                        tableData.reload()
                                        layer.msg('操作成功！', {
                                            icon: 1,
                                            time: 1500
                                        });
                                    }
                                }
                            })
                            })
                        } else if(val=='2') {
                            sDirectorLeaderStatus = 2  //退回等于2
                            layer.confirm('是否确认退回？', function (index) {
                                $.ajax({
                                    url: '/rpmTopic/updateRpmTopic',
                                    dataType: 'json',
                                    type: 'get',
                                    data:
                                        '&topicId=' + obj.data.topicId
                                        + '&planId=' + obj.data.planId
                                        + '&userId=' + data.userId
                                        + '&sDirectorLeaderStatus=' + sDirectorLeaderStatus,
                                    success: function (res) {
                                        if (res.flag) {
                                            layer.close(index)
                                            tableData.reload()
                                            layer.msg('操作成功！', {
                                                icon: 1,
                                                time: 1500
                                            });
                                        }
                                    }
                                })
                            })
                        }else {
                            sDirectorLeaderStatus = 8  //不通过等于8
                            layer.confirm('是否确认不通过？', function (index) {
                                $.ajax({
                                    url: '/rpmTopic/updateRpmTopic',
                                    dataType: 'json',
                                    type: 'get',
                                    data:
                                        '&topicId=' + obj.data.topicId
                                        + '&planId=' + obj.data.planId
                                        + '&userId=' + data.userId
                                        + '&sDirectorLeaderStatus=' + sDirectorLeaderStatus,
                                    success: function (res) {
                                        if (res.flag) {
                                            layer.close(index)
                                            tableData.reload()
                                            layer.msg('操作成功！', {
                                                icon: 1,
                                                time: 1500
                                            });
                                        }
                                    }
                                })
                            })
                        }
                    } else {
                        var userId = data.userId
                        var planId = data.planId
                        if(obj.event==="look")
                        $(this).attr('href', '/rpmPlan/reviewlook?type=1&userId=' + userId + '&planId=' + planId)
                    }
                });
                //查询
                $.ajax({
                    url: '/rpmTopic/selectByparentNo',
                    type: 'get',
                    dataType: 'json',
                    success: function (res) {
                        var research = res.data.researchType
                        var sectionType = res.data.sectionType
                        var strs = ''
                        var str = ''
                        //研究领域
                        for (var i = 0; i < research.length; i++) {
                            str += '<option value="' + research[i].dictNo + '">' + research[i].dictName + '</option>'
                        }
                        //项目类别
                        for (var i = 0; i < sectionType.length; i++) {
                            strs += '<option value="' + sectionType[i].dictNo + '">' + sectionType[i].dictName + '</option>'
                        }
                        $('select[name="research"]').append(str)
                        $('select[name="sectionType"]').append(strs);
                        form.render('select');
                    }
                })
                $('.search').click(function () {
                    tableData.reload({
                        where: {
                            teacheerStatus: $('input[name="status"]:checked').val(),
                            research: $('select[name="research"]').val(),
                            sectionType: $('select[name="sectionType"]').val()
                        }
                    })
                })


        });
</script>
